<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<html>
<title></title>
<body>
<%
   String realPath=request.getServletContext().getRealPath(request.getRequestURI());
   String path = request.getContextPath(); 
   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
   out.print(basePath);
   out.print(realPath);
//   out.print(path);
   String fileName = request.getParameter("fileName");//用request得到 	
   String filePath = request.getParameter("filePath");
   if(filePath==null){
	   filePath = "";
   }
   if(fileName==null){
	   fileName = "";
   }
%>

<%
String optionPath = realPath+filePath+fileName;
//out.print(optionPath);
File dir=new File(optionPath);
File file[]=dir.listFiles();//用file对象的listFiles()方法返回指定目录下的文件
%>
<h1><%=optionPath%></h1>
目录有:
<%
for(int i=0;i<file.length;i++)
{
  if(file[i].isDirectory()){
//	  String filePath =
	  String a = "<p><a href='"+request.getContextPath()+"\\all_news.jsp?fileName="+file[i].getName()+"'>"+file[i].getName()+"</a></p>";
	  out.print(a);
  }
}
%>
文件有:
<%
for(int i=0;i<file.length;i++)
{
    if(file[i].isFile())
		out.print("<p><a href='"+request.getContextPath()+"\\"+fileName+"\\"+file[i].getName()+"'>"+file[i].getName()+"</a></p>");
}
  %>
 
</body>
</html>